package server.controller.seal;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import server.db.primary.mapper.map.SealAppMapper;
import server.db.primary.mapper.map.SealMapper;
import server.db.primary.model.map.Seal;
import server.db.primary.model.map.SealApp;
import server.tool.Res;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
public class SealController {
    @Autowired
    SealMapper sealMapper;

    @Autowired
    SealAppMapper sealAppMapper;

    @RequestMapping("/Seal/Insert")
    public Res sealByInsert(Seal record) {
        int seal = sealMapper.insertSelective(record);
        return Res.success(seal);
    }

    @RequestMapping("/Seal/Updata")
    public Res sealByUpdata(Seal record) {
        int seal = sealMapper.updateByPrimaryKeySelective(record);
        return Res.success(seal);
    }

    @RequestMapping("/Seal/Delete")
    public Res sealByDelete(Long id) {
        int seal = sealMapper.deleteByPrimaryKey(id);
        return Res.success(seal);
    }

    @RequestMapping("/Seal/Id")
    public Res sealById(Long id) {
        Seal seal = sealMapper.selectByPrimaryKey(id);
        return Res.success(seal);
    }


    @RequestMapping("/Seal/numberId")
    public Res sealBynumberId() {
        List<Seal> seal = sealMapper.selectBynumberId();
        return Res.success(seal);
    }

    @RequestMapping("/Seal/userId")
    public Res sealByuserId(Integer userId,Integer mark1,String timeStart, String timeEnd) {
        List<Seal> seal = sealMapper.selectByuserId(userId,mark1,timeStart, timeEnd);
        return Res.success(seal);
    }

    @RequestMapping("/Seal/userIdMark")
    public Res sealByuserIdmark(Integer userId,String timeStart, String timeEnd) {
        List<Seal> seal = sealMapper.selectByuserIdmark(userId,timeStart, timeEnd);
        return Res.success(seal);
    }

    @RequestMapping("/Seal/notwelluserId")
    public Res sealnotBywelluserId(Integer userId,Integer wellUserId,String timeStart, String timeEnd,String timeStart1, String timeEnd1) {
        List<Seal> seal = sealMapper.selectnotBywelluserId(userId,wellUserId,timeStart, timeEnd,timeStart1, timeEnd1);
        return Res.success(seal);
    }

    @RequestMapping("/Seal/welluserId")
    public Res sealBywelluserId(Integer userId,Integer wellUserId,String timeStart, String timeEnd,String timeStart1, String timeEnd1) {
        List<Seal> seal = sealMapper.selectBywelluserId(userId,wellUserId,timeStart, timeEnd,timeStart1, timeEnd1);
        return Res.success(seal);
    }

    @RequestMapping("/Seal/welluserIdmark")
    public Res sealBywelluserIdmark(Integer userId,Integer wellUserId,String timeStart, String timeEnd,String timeStart1, String timeEnd1) {
        List<Seal> seal = sealMapper.selectBywelluserIdmark(userId,wellUserId,timeStart, timeEnd,timeStart1, timeEnd1);
        return Res.success(seal);
    }

    @RequestMapping("/Seal/notstationuserId")
    public Res sealnotBystationuserId(Integer stationUserId,String timeStart, String timeEnd) {
        List<Seal> seal = sealMapper.selectnotBystationuserId(stationUserId,timeStart, timeEnd);
        return Res.success(seal);
    }

    @RequestMapping("/Seal/stationuserId")
    public Res sealBystationuserId(Integer stationUserId,String timeStart, String timeEnd) {
        List<Seal> seal = sealMapper.selectBystationuserId(stationUserId,timeStart, timeEnd);
        return Res.success(seal);
    }

    @RequestMapping("/Seal/stationuserIdmark")
    public Res sealBystationuserIdmark(Integer stationUserId,String timeStart, String timeEnd) {
        List<Seal> seal = sealMapper.selectBystationuserIdmark(stationUserId,timeStart, timeEnd);
        return Res.success(seal);
    }

    @RequestMapping("/Seal/mark")
    public Res sealBymark(String timeStart, String timeEnd) {
        List<Seal> seal = sealMapper.selectBymark(timeStart, timeEnd);
        return Res.success(seal);
    }

    @RequestMapping("/Seal/notmark")
    public Res sealBynotmark(Integer mark,String timeStart, String timeEnd) {
        List<Seal> seal = sealMapper.selectnotBymark(mark,timeStart, timeEnd);
        return Res.success(seal);
    }

    @RequestMapping("/Seal/selectSealApp")
    public Res selectSealApp(Long id) {
        /**
         * 根据id查找,返回流水号
         */
        Seal seal = sealMapper.selectByPrimaryKey(id);
        /**
         * 流水号
         */
        Long numberId = seal.getNumberId();
        /**
         * 、、、
         * 根据流水号查找对应的附件全部传到前端
         */
        List<SealApp> sealApps = sealAppMapper.selectByNumberId(numberId);
        Map<String, Object> map = new HashMap<>();
        map.put("seal", seal);
        return Res.success(map);
    }
}
